home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / business / stata2 / stat.kit < prev    next >
Encoding:
Text File  |  1988-08-16  |  18.4 KB  |  728 lines

  1. set output error
  2.  
  3. display _new in blue /*
  4. */ "Loading Stat.Kit Release 2.0  Demonstration Version" _n /*
  5. */ "Copyright (c) 1987-1988 by ==C=R=C==.  All rights reserved."
  6.  
  7.  
  8.  
  9.  
  10. /*
  11.   User's wishing to edit Stat.Kit please see comments at end of this file.
  12.  
  13.  
  14.     utility routines used by various programs:
  15. */
  16.  
  17. capture program drop _nmusig2
  18. program define _nmusig2
  19.     capture {
  20.         sum %_1 %_5 %_6
  21.         gen int %_2 = _result(1) in l
  22.         gen double %_3 = _result(3) in l
  23.         gen double %_4 = _result(4) in l
  24.         exit
  25.     }
  26.     capture drop %_2
  27.     capture drop %_3
  28.     capture drop %_4
  29.     BREAK
  30. end
  31.  
  32. /*
  33.     top level programs
  34. */
  35.  
  36. capture program drop ttest
  37. program define ttest
  38.     if "%_*"=="" {
  39.         di in blue "-> ttest varname = #"
  40.         di in blue "-> ttest varname = varname[, equal unequal paired]"
  41.         exit
  42.     }
  43.     mac def _varlist "req ex max(1)"
  44.     mac def _exp "req noprefix"
  45.     mac def _in "opt"
  46.     mac def _if "opt"
  47.     mac def _options "Equal Unequal Paired"
  48.     parse "%_*"
  49.     capture conf numb %_exp
  50.     if _rc==0 {
  51.         if "%_equal`%_unequal`%_paired"~="" {
  52.             di in red /*
  53.             */ "options not allowed when testing against constant."
  54.             exit
  55.         }
  56.         _ttmean %_varlist %_exp "%_if" "%_in"
  57.         exit
  58.     }
  59.     conf var %_exp
  60.     parse "%_equal %_unequal %_paired", parse(" ")
  61.     if "%_2"!="" {
  62.         di in red "%_* ?"
  63.         exit
  64.     }
  65.     if "%_unequal"!="" {
  66.         _ttneq %_varlist %_exp "%_if" "%_in"
  67.         exit
  68.     }
  69.     if "%_paired"!="" {
  70.         _ttpair %_varlist %_exp "%_if" "%_in"
  71.         exit
  72.     }
  73.     _tteq %_varlist %_exp "%_if" "%_in"
  74. end
  75.  
  76.  
  77. capture program drop _tteq
  78. program define _tteq
  79.     capture {
  80.         _nmusig2 %_1 _N1 _M1 _V1 "%_3" "%_4"
  81.         _nmusig2 %_2 _N2 _M2 _V2 "%_3" "%_4"
  82.         #delimit ;
  83.         mac def _tstat=(_M1-_M2) / (
  84.                sqrt(((_N1-1)*_V1+(_N2-1)*_V2)/(_N1+_N2-2)) *
  85.                sqrt(1/_N1+1/_N2)
  86.                ) in l ;
  87.         noisily sum %_1 %_2 %_3 %_4 ;
  88.         di _n in g
  89.        "Test: means of %_1 and %_2 are equal (assuming equal variances)"
  90.             _n ;
  91.         di in g " Difference = " in y _M1[_N]-_M2[_N] ;
  92.         di in g "t-statistic = " in y %5.2f %_tstat in g " with "
  93.            in y _N1[_N]+_N2[_N]-2 in g " d.f." ;
  94.         di in gr " Prob > |t| = " in ye %6.4f
  95.            max(tprob(_N1[_N]+_N2[_N]-2,%_tstat),.0001) ;
  96.         #delimit cr
  97.     }
  98.     if _rc {
  99.         di in red "--Break--"
  100.     }
  101.     capture drop _N1 _M1 _V1
  102.     capture drop _N2 _M2 _V2
  103. end
  104.  
  105. capture program drop _ttmean
  106. program define _ttmean
  107.     sum %_1 %_3 %_4
  108.     mac def _ts=(_result(3)-(%_2))*sqrt(_result(1))/sqrt(_result(4)) in l
  109.     di _n _sk(9) in gr "Test: mean of %_1 = " in ye "%_2"
  110.     #delimit ;
  111.     di _sk(15) in gr "t-statistic = " in y %5.2f %_ts in gr " with "
  112.         in y _result(1)-1 in g " d.f." ;
  113.     #delimit cr
  114.     di _sk(15) in gr "Prob > |t|  = ",in ye %6.4f tprob(_result(1)-1,%_ts)
  115. end
  116.  
  117. capture program drop _ttneq
  118. program define _ttneq
  119.     capture {
  120.         _nmusig2 %_1 _N1 _M1 _V1 "%_3" "%_4"
  121.         _nmusig2 %_2 _N2 _M2 _V2 "%_3" "%_4"
  122.         mac def _tstat=(_M1-_M2)/sqrt((_V1/_N1)+(_V2/_N2)) in l
  123.         #delimit ;
  124.         mac def _dof=int((((_V1/_N1)+(_V2/_N2))^2)/(
  125.             ((_V1/_N1)^2)/(_N1+1)+((_V2/_N2)^2)/(_N2+1)
  126.             )-1.5) in l ;
  127.         noisily sum %_1 %_2 %_3 %_4;
  128.         di _n in gr
  129.          "Test: means of %_1 and %_2 are equal (unequal variances)" _n;
  130.         di in gr " Difference = " in ye _M1[_N]-_M2[_N] ;
  131.         di in gr "t-statistic = " in ye %5.2f %_tstat in gr " with "
  132.            in ye %_dof in gr " d.f." ;
  133.         di in gr " Prob > |t| = "
  134.            in ye %6.4f max(tprob(%_dof,%_tstat),.0001) ;
  135.         #delimit cr
  136.     }
  137.     if _rc {
  138.         di in red "--Break--"
  139.     }
  140.     capture drop _N1 _M1 _V1
  141.     capture drop _N2 _M2 _V2
  142. end
  143.  
  144.  
  145. capture program drop _ttpair
  146. program define _ttpair
  147.     capture {
  148.         gen double _DIFF=%_1-%_2
  149.         _nmusig2 _DIFF _CNT _MEAN _VAR
  150.         mac def _tstat=(_MEAN*sqrt(_CNT))/sqrt(_VAR) in l
  151.         noisily sum %_1 %_2 if %_1~=. & %_2~=.
  152.         #delimit ;
  153.         di _n in gr
  154.           "Test: means of %_1 and %_2 are equal (paired observations)" _n;
  155.         di in gr " Difference = " in ye _MEAN[_N] ;
  156.         di in gr "t-statistic = " in ye %5.2f %_tstat in gr " with "
  157.            in ye _CNT[_N]-1 in gr " d.f." ;
  158.         di in gr " Prob > |t| = "
  159.            in ye %6.4f max(tprob(_CNT[_N]-1,%_tstat),.0001) ;
  160.         #delimit cr
  161.     }
  162.     if _rc {
  163.         di in red "--Break--"
  164.     }
  165.     capture drop _DIFF
  166.     capture drop _CNT _MEAN _VAR
  167. end
  168.  
  169.  
  170. capture program drop teststd
  171. program define teststd
  172.     if "%_*"=="" {
  173.         di in blu "-> teststd varname = {varname | number}"
  174.         exit
  175.     }
  176.     mac def _varlist "req ex max(1)"
  177.     mac def _exp "req noprefix"
  178.     mac def _in "opt"
  179.     mac def _if "opt"
  180.     parse "%_*"
  181.     capture conf numb %_exp
  182.     if _rc==0 {
  183.         _tscon %_varlist %_exp "%_if" "%_in"
  184.         exit
  185.     }
  186.     conf var %_exp
  187.     _tsvar %_varlist %_exp "%_if" "%_in"
  188. end
  189.  
  190. capture program drop _tscon
  191. program define _tscon
  192.     sum %_1 %_3 %_4
  193.     quietly {
  194.         mac def _c2=(_result(1)-1)*(_result(4)/((%_2)^2))
  195.         mac def _p = max(chiprob(_result(1)-1,(%_c2)+(1e-20)),.0001)
  196.         di _n in gr "Test: standard deviation of %_1 = %_2`:" _n
  197.         #delimit ;
  198.         di in gr " chi-square = " in ye %5.2f %_c2 in gr " with "
  199.            in ye _result(1)-1 in gr " d.f." ;
  200.         di in gr "probability = " in ye %6.4f min(%_p,1-(%_p))
  201.            in gr " (one-tailed test)" ;
  202.         #delimit cr
  203.     }
  204. end
  205.  
  206. capture program drop _tsvar
  207. program define _tsvar
  208.     sum %_1 %_2 %_3 %_4
  209.     capture {
  210.         _nmusig2 %_1 _N1 _M1 _V1 "%_3" "%_4"
  211.         _nmusig2 %_2 _N2 _M2 _V2 "%_3" "%_4"
  212.         mac def _f=_V1/_V2 in l
  213.         if _V1[_N]<_V2[_N] {
  214.             mac def _f=_V2/_V1 in l
  215.             mac def _h=_N1 in l
  216.             replace _N1=_N2 in l
  217.             replace _N2=%_h in l
  218.         }
  219.         di in gr _n "Test: variances of %_1 and %_2 are equal" _n
  220.         #delimit ;
  221.         di in gr "F-statistic = " in ye %6.3f %_f in gr " with ("
  222.            in ye _N1[_N]-1 in gr "," in ye _N2[_N]-1 in gr ") d.f.";
  223.         di in gr "   Prob > F = "
  224.            in ye %6.4f max(fprob(_N1[_N]-1,_N2[_N]-1,%_f),.0001) ;
  225.         #delimit cr
  226.     }
  227.     if _rc {
  228.         di in red "--Break--"
  229.     }
  230.     capture drop _N1 _M1 _V1
  231.     capture drop _N2 _M2 _V2
  232. end
  233.  
  234. capture program drop genstd
  235. program define genstd
  236.     if "%_*"=="" {
  237.         di in bl "-> genstd newvar = exp [if] [in], mean(#) std(#)"
  238.         exit
  239.     }
  240.     mac def _varlist "req new max(1)"
  241.     mac def _exp "req noprefix"
  242.     mac def _options "Mean(real 0) Std(real 1)"
  243.     mac def _if "opt"
  244.     mac def _in "opt"
  245.     parse "%_*"
  246.     quietly {
  247.         replace %_varlist = %_exp %_in %_if
  248.         quietly sum %_varlist
  249.         #delimit ;
  250.         replace %_varlist =
  251.              ((%_varlist-_result(3))/sqrt(_result(4)))*(%_std)
  252.              + (%_mean) ;
  253.         #delimit cr
  254.         label var %_varlist "Standardized values of %_exp"
  255.     }
  256. end
  257.  
  258. capture program drop spearman
  259. program define spearman
  260.     if "%_*"=="" {
  261.         di in blue "-> spearman var1 var2 [if] [in]"
  262.         exit
  263.     }
  264.     mac def _varlist "req ex min(2) max(2)"
  265.     mac def _if "opt"
  266.     mac def _in "opt"
  267.     parse "%_*"
  268.     parse "%_varlist", parse(" ")
  269.     capture {
  270.         genrank _SP1 = %_1 %_if %_in
  271.         conf var _SP1
  272.         genrank _SP2 = %_2 %_if %_in
  273.         conf var _SP2
  274.     }
  275.     if _rc==0 {
  276.         ren %_1 _SP3
  277.         ren %_2 _SP4
  278.         ren _SP1 %_1
  279.         ren _SP2 %_2
  280.         capture noisily {
  281.             di _n in green "Spearman Rank Correlation"
  282.             corr %_1 %_2
  283.         }
  284.         drop %_1 %_2
  285.         ren _SP3 %_1
  286.         ren _SP4 %_2
  287.     }
  288. end
  289.  
  290. capture program drop signtest
  291. program define signtest
  292.     if "%_*"=="" {
  293.         di in blue "-> signtest var1 = exp [if] [in]"
  294.         exit
  295.     }
  296.     mac def _varlist "req ex max(1)"
  297.     mac def _exp "req noprefix"
  298.     mac def _if "opt"
  299.     mac def _in "opt"
  300.     parse "%_*"
  301.     set out e
  302.     di _n in gr "Test: Equality of medians (Matched Sample Sign Test)" _n
  303.     capture {
  304.         gen int _Dif=sign((%_varlist)-(%_exp)) %_if %_in
  305.         count if _Dif==0
  306.         mac def _zer = _result(1)
  307.         count if _Dif==1
  308.         mac def _pos = _result(1)+(%_zer)/2
  309.         count if _Dif==-1
  310.         mac def _neg = _result(1)+(%_zer)/2
  311.         mac def _z=((%_pos)-(%_neg))/sqrt((%_pos)+(%_neg))
  312.         drop _Dif
  313.     }
  314.     if _rc==1 {
  315.         di in red "--Break--"
  316.         capture drop _Dif
  317.         exit
  318.     }
  319.     di in gr "Result of %_varlist - (%_exp) %_if %_in"
  320.     di in gr " -------------------"
  321.     di in gr " Positive " in ye %10.0g %_pos
  322.     di in gr " Negative " in ye %10.0g %_neg
  323.     di in gr " -------------------"
  324.     di in gr " Total    " in ye %10.0g %_pos+%_neg _n
  325.     di in gr "Exact 5%` test:  Reject if smaller frequency from table above"
  326.     #delimit ;
  327.     di in gr " is less than " in ye
  328.        int((%_pos+%_neg-1)/2-.98*sqrt(%_pos+%_neg+1)+.5)," (+/- 1)" _n;
  329.     di in gr "Normal Approximation:";
  330.     di in gr " z-statistic " in ye %6.3f %_z ;
  331.     di in gr " Prob > |z|  " in ye %6.4f max(normprob(-abs(%_z))*2,.0001) ;
  332.     #delimit cr
  333. end
  334.  
  335. capture program drop signrank
  336. program define signrank
  337.     if "%_*"=="" {
  338.         di in blue "-> signrank var = exp [if] [in]"
  339.         exit
  340.     }
  341.     mac def _varlist "req ex max(1)"
  342.     mac def _exp "req noprefix"
  343.     mac def _if "opt"
  344.     mac def _in "opt"
  345.     parse "%_*"
  346.     capture {
  347.         genrank _R=abs(%_varlist-(%_exp)) %_if %_in
  348.         gen _R0=sum(cond(sign(%_varlist-(%_exp))==0,_R,0))
  349.         gen _Rp=sum(cond(sign(%_varlist-(%_exp))==1,_R,0))+_R0/2
  350.         gen _Rn=sum(cond(sign(%_varlist-(%_exp))==-1,_R,0))+_R0/2
  351.         gen int _C=sum(_R~=.)
  352.         drop _R
  353.         #delimit ;
  354.         di _n in gr
  355.         "Test:  Equality of distributions (Wilcoxon Signed-Ranks)" _n ;
  356.         di in gr "Result of %_varlist - (%_exp) %_if %_in" _n
  357.              " Sum of Positive Ranks = " in ye _Rp[_N] _n
  358.            in gr " Sum of Negative Ranks = " in ye =_Rn[_N] _n ;
  359.         drop _R0 _Rn ;
  360.         mac def _z=(_Rp-(_C*(_C+1)/4))/sqrt(_C*(_C+1)*(2*_C+1)/24) in l;
  361.         di in gr " z-statistic " in ye %6.2f %_z _n
  362.            in gr " Prob > |z|  " in ye
  363.            %8.4f max(normprob(-abs(%_z))*2,.0001);
  364.         drop _Rp _C;
  365.         #delimit cr
  366.     }
  367.     if _rc == 1 {
  368.         di in red "--Break--"
  369.         capture drop _R
  370.         capture drop _R
  371.         capture drop _R0
  372.         capture drop _Rn
  373.         capture drop _Rp
  374.         capture drop _C
  375.     }
  376. end
  377.  
  378. capture program drop regdw
  379. program define regdw
  380.     if "%_*"=="" {
  381.         di in bl /* 
  382.          */    "-> regdw lhsvar rhsvar rhsvar ... [, regress_options ] "
  383.         exit
  384.     }
  385.     reg %_*
  386.     quietly {
  387.         predict double _RES, res
  388.         gen double _DW=sum((_RES-_RES[_n-1])^2)/sum(_RES*_RES)
  389.         di in gr "Durbin Watson Statistic = " in ye _DW[_N]
  390.         drop _DW _RES
  391.     }
  392. end
  393.  
  394. capture program drop ranksum
  395. program define ranksum
  396.     di in blue "not available in demonstration version"
  397. end
  398.  
  399. capture program drop genrank
  400. program define genrank
  401.     if "%_*"=="" {
  402.         di in bl "-> genrank varname = exp [if] [in]"
  403.         exit
  404.     }
  405.     mac def _varlist "req new max(1)"
  406.     mac def _exp "req nopre"
  407.     mac def _if "opt"
  408.     mac def _in "opt"
  409.     parse "%_*"
  410.     capture {
  411.         gen _GRV = %_exp %_if %_in
  412.         sort _GRV
  413.         gen int _GRr = cond(_GRV==_GRV[_n-1],_GRr[_n-1],_n) if _GRV~=.
  414.         by _GRV: replace %_varlist = _GRr+(_N-1)/2
  415.         drop _GRV _GRr
  416.         label var %_varlist "Rank of %_exp"
  417.     }
  418.     if _rc==1 {
  419.         di in red "--Break--"
  420.         capture drop _GRV
  421.         capture drop _GRr
  422.         capture drop %_varlist
  423.     }
  424. end
  425.  
  426.  
  427. capture program drop means
  428. program define means
  429.     mac def _varlist "opt ex"
  430.     mac def _if "opt"
  431.     mac def _in "opt"
  432.     parse "%_*"
  433.     parse "%_varlist", parse(" ")
  434.     #delimit ;
  435.     di _new in gr _col(10) "|" _col(17) "Arithmetic" _col(35) "Geometric"
  436.          _col(54) "Harmonic" ;
  437.     di in gr _col(10) "|" _col(12) _dup(3) "     Mean   Obs   " ;
  438.     di in gr _dup(9) "-" "+" _dup(52) "-" ;
  439.     #delimit cr
  440.     quietly {
  441.         while "%_1"~="" {
  442.             capture {
  443.                 gen double _VAR = %_1 %_if %_in
  444.                 quietly sum _VAR
  445.                 mac def _acnt = _result(1)
  446.                 mac def _amea = _result(3)
  447.                 gen double _VAR2=log(_VAR)
  448.                 summarize _VAR2
  449.                 mac def _gcnt = _result(1)
  450.                 mac def _gmea = exp(_result(3))
  451.                 replace _VAR2 = sum(cond(_VAR>0,1/_VAR,0))
  452.                 #delimit ;
  453.                 di in gr "%_1" _col(10) "|",in ye
  454.                    %9.0g %_amea,%5.0f %_acnt,
  455.                    "  " %9.0g %_gmea,%5.0f %_gcnt,
  456.                    "  " %9.0g %_gcnt/_VAR2[_N],%5.0f %_gcnt ;
  457.                 #delimit cr
  458.             }
  459.             if _rc {
  460.                 di in red "--Break--"
  461.                 capture drop _VAR
  462.                 capture drop _VAR2
  463.                 exit
  464.             }
  465.             drop _VAR _VAR2
  466.             mac shift
  467.         }
  468.     }
  469. end
  470.  
  471. capture program drop kwallis
  472. program define kwallis
  473.     if "%_*"=="" {
  474.         di in bl "-> kwallis varname [if] [in], by(grouping_var_name)"
  475.         exit
  476.     }
  477.     mac def _varlist "req ex max(1)"
  478.     mac def _options "BY(string)"
  479.     mac def _if "opt"
  480.     mac def _in "opt"
  481.     parse "%_*"
  482.     if "%_by"=="" {
  483.         di in red "You must specify the grouping variable"
  484.         kwallis
  485.         exit
  486.     }
  487.     confirm var %_by
  488.     capture {
  489.         genrank _RankSum = %_varlist %_if %_in  /* ranks right now */
  490.         gen int _Obs=1 if _RankSum~=.
  491.         sort %_by
  492.         by %_by: replace _RankSum=cond(_n==_N,sum(_RankSum),.)
  493.         by %_by: replace _Obs=cond(_n==_N,sum(_Obs),.)
  494.         by %_by: gen int _Grp=1 if _n==_N & _Obs>0
  495.         replace _Grp=sum(_Grp)
  496.         di _n in gr /*
  497.         */ "Test: Equality of populations (Kruskal-Wallis Test)"
  498.         format _RankSum %9.2f
  499.         noisily l %_by _Obs _RankSum if _Obs~=. & _Obs~=0, noobs
  500.         replace _RankSum=sum(_RankSum*_RankSum/_Obs)
  501.         replace _Obs=sum(_Obs)
  502.         mac def _K=12/(_Obs*(_Obs+1))*_RankSum-3*(_Obs+1) in l
  503.         #delimit ;
  504.         di _new in gr " chi-square = " in ye %9.3f %_K
  505.             in gr " with " in ye _Grp[_N]-1 in gr " d.f." ;
  506.         di in gr "probability = " in ye
  507.             %10.4f max(chiprob(_Grp[_N]-1,%_K+(1e-20)),.0001) ;
  508.         #delimit cr
  509.         drop _Obs _RankSum _Grp
  510.     }
  511.     if _rc==1 {
  512.         di in red "--Break--"
  513.         capture drop _Obs
  514.         capture drop _RankSum
  515.         capture drop _Grp
  516.     }
  517. end
  518.  
  519. capture program drop ksmirnov
  520. program define ksmirnov
  521.     if "%_*"=="" {
  522.         di in blue "->ksmirnov var = exp [if] [in] [, onesamp]"
  523.         exit
  524.     }
  525.     mac def _varlist "req ex max(1)"
  526.     mac def _exp "req noprefix"
  527.     mac def _if "opt"
  528.     mac def _in "opt"
  529.     mac def _options "Onesamp"
  530.     parse "%_*"
  531.     parse "%_varlist", parse(" ")
  532.     di _n in gr "Test: Equality of Distribution Functions (Kolmogorov-Smirnov)" _n
  533.     capture {
  534.         gen _G1 = (%_1!=.) %_if %_in
  535.         replace _G1 = (_G1==1)
  536.         gen _v = %_exp %_if %_in
  537.         if "%_onesamp"=="" {
  538.             gen _G2 = 1 if _v!=.
  539.             replace _v = %_1 if _v==.
  540.             sort _v
  541.             replace _G1 = sum(_G1)
  542.             mac def _m = _G1[_N]
  543.             replace _G1 = _G1 / %_m
  544.             replace _G2 = sum(_G2)
  545.             mac def _k = _G2[_N]
  546.             replace _G2 = _G2 / %_k
  547.             replace _G1 = _G1 - _G2
  548.             by _v: replace _G1 = _G1[_N]
  549.         }
  550.         if "%_onesamp"~="" {
  551.             sort %_1
  552.             replace _G1 = sum(_G1)
  553.             mac def _m = _G1[_N]
  554.             replace _G1 = _G1 / %_m
  555.             replace _G1 = _G1 - _v
  556.             mac def _k = 10e6
  557.         }
  558.         summarize _G1
  559.         mac def _Dm = _result(5)
  560.         mac def _Dp = _result(6)
  561.         if "%_onesamp"~="" {
  562.             mac def _Dm = %_Dm - 1/%_m
  563.             }
  564.         mac def _D = max(-%_Dm,%_Dp)
  565.         mac def _A = %_m*%_k/(%_m+%_k)
  566.         mac def _Pm = exp(-2*%_A*%_Dm^2)
  567.         mac def _Pp = exp(-2*%_A*%_Dp^2)
  568.         mac def _Z2 = %_A*(%_D^2)
  569.         mac def _P = exp(-2*%_Z2) - exp(-8*%_Z2) + exp(-18*%_Z2) /*
  570.                 */ - exp(-32*%_Z2) + exp(-50*%_Z2)
  571.         mac def _P = min(2*%_P, 1)
  572.         mac def _Pc = %_P
  573.         if %_P<1 {
  574.             mac def _Pz = invnorm(%_P)+1.04/min(%_m,%_k) /*
  575.                  */ +2.09/max(%_m,%_k)-1.35/sqrt(%_A)
  576.             mac def _Pc = normprob(%_Pz)
  577.         }
  578.         drop _G1 _G2 _v
  579.     }
  580.     if _rc==1 {
  581.         di in red "--Break--"
  582.         capture drop _G1
  583.         capture drop _G2
  584.         capture drop _v
  585.         exit
  586.     }
  587.     mac def _exp = substr("%_exp",1,8)
  588.     di in gr " Smaller group       D      P-value  Corrected"
  589.     di in gr " " _dup(45) "-"
  590.     di in gr " %_1:" _col(20) in ye %8.4f %_Dp %8.3f %_Pp
  591.     di in gr " %_exp:" _col(20) in ye %8.4f %_Dm %8.3f %_Pm
  592.     di in gr " Combined K-S:" _col(20) in ye %8.4f %_D  %8.3f %_P %8.3f %_Pc
  593. end
  594.  
  595.  
  596.  
  597. capture program drop gprobit
  598. program define gprobit
  599.     if "%_*"=="" {
  600.         di in bl "-> gprobit successes population rhs-vars... [if] [in]"
  601.         exit
  602.     }
  603.     mac def _varlist "req ex"
  604.     mac def _if "opt"
  605.     mac def _in "opt"
  606.     parse "%_*"
  607.     parse "%_varlist", parse(" ")
  608.     quietly {
  609.         gen long _S=%_1 if %_1>=0
  610.         gen long _P=%_2 if %_2>=0 & %_1<=%_2
  611.         gen double _PROBIT=invnorm(_S/_P) %_if %_in
  612.     }
  613.     di _n in gr "Minimum chi-square probit estimates for grouped data:"
  614.     mac shift
  615.     mac shift
  616.     reg _PROBIT %_* =(exp(-_PROBIT^2)/(2*_pi))*(_P/((_S/_P)*((_P-_S)/_P)))
  617.     drop _PROBIT _S _P
  618. end
  619.  
  620. capture program drop glogit
  621. program define glogit
  622.     if "%_*"=="" {
  623.         di in bl "-> glogit successes population rhs-vars... [if] [in]"
  624.         exit
  625.     }
  626.     mac def _varlist "req ex min(2)"
  627.     mac def _if "opt"
  628.     mac def _in "opt"
  629.     parse "%_*"
  630.     parse "%_varlist", parse(" ")
  631.     quietly {
  632.         gen long _S=%_1 if %_1>=0
  633.         gen long _F=%_2-%_1 if %_2>=0 & %_2>%_1
  634.         gen double _LOGIT=log(_S/_F) %_if %_in
  635.     }
  636.     di _n in gr "Minimum chi-square logit estimates for grouped data:"
  637.     mac shift
  638.     mac shift
  639.     reg _LOGIT %_* =(_S*_F)/(_S+_F)
  640.     drop _LOGIT _S _F
  641. end
  642.  
  643. capture program drop dbeta
  644. program define dbeta
  645.     if "%_3"=="" {
  646.         di in bl "-> dbeta lhs rhs other-rhs [if] [in], gen(newvar)"
  647.         exit
  648.     }
  649.     mac def _varlist "req ex min(2)"
  650.     mac def _if "opt"
  651.     mac def _in "opt"
  652.     mac def _options "Generate(string)"
  653.     parse "%_*"
  654.     if "%_generat"=="" {
  655.         dbeta
  656.         exit
  657.     }
  658.     conf new var %_generat
  659.     parse "%_varlist", parse(" ")
  660.     mac def _lhs %_1
  661.     mac shift
  662.     quietly {
  663.         reg %_* %_if %_in
  664.         pred double _RES %_if %_in, res
  665.         noisily reg %_lhs %_* %_if %_in
  666.         pred double _HAT %_if %_in, hat
  667.         pred double _RSTU %_if %_in, rstud
  668.         gen double _SRES=sum(_RES^2)
  669.         gen %_generat=_RSTU*_RES/sqrt((1-_HAT)*_SRES[_N])
  670.     }
  671.     drop _RES _HAT _RSTU _SRES
  672.     label var %_generat "DF-Betas for %_1"
  673.     di _n in bl "(%_generat now contains DF-Betas for %_1)"
  674. end
  675.  
  676.  
  677. di
  678. di in gr "The following new commands are now available:"
  679. di "   dbeta          glogit         kwallis        regdw          spearman"
  680. di "   genrank        gprobit        means          signrank       teststd"
  681. di "   genstd         ksmirnov       ranksum        signtest       ttest"
  682. di _n in gr "See " in wh "help stat.kit" in gr "."
  683. exit
  684.  
  685. di "   xxxxxxxxxxxx   xxxxxxxxxxxx   xxxxxxxxxxxx   xxxxxxxxxxxx   xxxxxxxxxxxx"
  686.  
  687. Notes to User's wishing to edit this file:
  688.  
  689. These comments are placed at the end of the file, after the exit, so that
  690. Stata does not have to read through them every time the user types "run
  691. Stat.Kit"
  692.  
  693. Feel free to edit this file and delete programs in which you have no interest.
  694. Before editing this file, however, make sure the the original is BACKED UP.
  695. Please do not remove the copyright notice at the top of this file.
  696.  
  697. If you do edit the file, you should add a display command at the top of this
  698. file indicating that you have edited the file.  You should change the display
  699. just above these comments that lists the new commands now available.
  700.  
  701. All utility programs start with an underscore '_'.
  702.  
  703. Some programs use other programs in achieving the desired result.  Review the
  704. table below carefully before deleting programs.
  705.  
  706.         Program         Requires
  707.         --------------------------
  708.         dbeta
  709.         genrank
  710.         genstd
  711.         glogit
  712.         gprobit
  713.         ksmirnov
  714.         kwallis         genrank
  715.         means
  716.         ranksum         genrank
  717.         regdw
  718.         signrank        genrank
  719.         signtest
  720.         spearman        genrank
  721.         teststd        _nmusig2 _tscon _tsvar
  722.         ttest          _nmusig2 _tteq _ttneq _ttpair _ttmean
  723.  
  724. For instance, if you deleted the genrank program, you would break kwallis,
  725. ranksum, signrank, and spearman.
  726.  
  727. <end of Stat.Kit>
  728.